package com.alpha.eceasy.mall.controller.open;

import com.alpha.eceasy.auth.UserLoginDTO;
import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.service.MallCustomerService;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@Hidden
@RequestMapping(value = "/open/customer", produces = MediaType.APPLICATION_JSON_VALUE)
@Tag(description = "customer", name = "客户表")
public class MallCustomerOpen {
    @Resource
    private MallCustomerService mallCustomerService;

    /**
     * 内部登录专用
     *
     * @param dto 用户详情
     * @return 成功与否
     */
    @Operation(description = "登录", summary = "登录")
    @PostMapping("/login")
    public R<String> login(@RequestBody @Validated UserLoginDTO dto) {
        log.info("login: {}", dto);
        String token = mallCustomerService.login(dto);
        log.info("login: {}", token);
        return R.ok(token);
    }
}
